package ReflectTest;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.TypeVariable;

/*
反射Method,反编译一个类的属性和方法
 */
public class ReflectMethodTest1 {
    public static void main(String[] args) {
        try {
            StringBuilder builder = new StringBuilder();
            Class c = Class.forName("java.lang.String");
            Field[] fields = c.getDeclaredFields();
            builder.append("public class "+c.getSimpleName()+"{\n");
            for(Field field : fields){
                builder.append("\t");
                builder.append(Modifier.toString(field.getModifiers()));
                builder.append(" ");
                builder.append(field.getType().getSimpleName());
                builder.append(" ");
                builder.append(field.getName()+";\n");
            }
            Method[] methods = c.getDeclaredMethods();
            for(Method method : methods){
                builder.append("\t");
                builder.append(Modifier.toString(method.getModifiers()));
                builder.append(" ");
                builder.append(method.getReturnType().getSimpleName());
                builder.append(" ");
                builder.append(method.getName());
                builder.append("(");
                Class[] Class = method.getParameterTypes();
                for(Class cl : Class){
                    builder.append(cl.getSimpleName());
                    builder.append(",");
                }
                if(builder.charAt(builder.length() - 1) == ','){
                    builder.deleteCharAt(builder.length() - 1);
                }
                builder.append("){}\n");
            }
            builder.append("}");
            System.out.println(builder);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
